package com.lhy.tool.generator.impl;

import com.lhy.tool.autoconfigation.GeneratorProperties;
import com.lhy.tool.generator.AbstractJavaGenerator;
import com.lhy.tool.model.Clazz;
import com.lhy.tool.model.CrudBean;
import com.lhy.tool.model.CrudColumn;
import com.lhy.tool.model.JavaAttribute;

import java.io.File;
import java.util.List;

public class DefaultMapperXmlGenerator extends AbstractJavaGenerator {

    private List<CrudColumn> columns;

    @Override
    protected Clazz curClazz(JavaAttribute javaAttribute) {
        return javaAttribute.getMapperXml();
    }

    /**
     * {@inheritDoc}
     *
     * @Description: 写入属性 查询条件列
     */
    @Override
    protected void writeJavaAttribute(CrudBean crudBean, GeneratorProperties generatorProperties) {
        columns = crudBean.getColumns();
    }

    @Override
    protected String projectPath(GeneratorProperties.Project project) {
        return project.getJavaProjectPath();
    }

    @Override
    protected String templateName() {
        return "TemplateMapper.xml.ftl";
    }

    /**
     * 生成的代码文件
     */
    @Override
    protected File getCodeFile() {
        Clazz curClazz = this.curClazz(getJavaAttribute());
        String packageName = curClazz.getPackageName();
        String filePath = this.getFileAttribute().getProjectPath() + "/src/main/java/" + packageName.replaceAll("\\.", "/")
                + "/" + curClazz.getName() + ".xml";
        return new File(filePath);
    }
}
